<template>
  <view>
    <uni-list>
      <uni-list-chat v-for="(item,index) in list"
                     :key="index" :avatar-circle="true" :avatar="item.studentPhoto"
                     :title="item.studentName" :note="item.date + ' ' + item.timeSlotText">
        <view style="display: flex">
          <!-- item.status 1 正常  2 迟到  3 请假 -->
          <uni-badge :type="item.status === '1' ? 'success' : (item.status === '2' ? 'error' : 'warning')" :text="item.statusText"
                     size="normal" style="margin-top: 10px;align-items: center;justify-content: center" :custom-style="{fontSize: '13px'}" />
        </view>
      </uni-list-chat>
    </uni-list>
  </view>
</template>

<script>
import UniList from "../../uni_modules/uni-list/components/uni-list/uni-list.vue";
import student from '@/api/modules/student';
import UniListChat from "../../uni_modules/uni-list/components/uni-list-chat/uni-list-chat.vue";
import UniListItem from "../../uni_modules/uni-list/components/uni-list-item/uni-list-item.vue";

export default {
  name: "classAttendance",
  components: {UniListItem, UniListChat, UniList},
  data(){
    return {
      requestParams: {
        page: 1,
        pageSize: 15,
        studentId: null,
      },
      maxPageNum: 1,
      list: [],
    }
  },
  created(){
    this.requestParams.studentId = this.getStorage("loginId");
    console.log("studentId",this.requestParams.studentId);
  },
  onShow(){
    this.getList(false);
  },
  onReachBottom() {
    if(this.requestParams.page >= this.maxPageNum){
      return;
    }
    this.requestParams.page++;
    console.log("onReachBottom page:{},maxPageNum:{}",this.requestParams.page,this.maxPageNum)
    this.getList(true);
  },

  methods: {
    getList(append){
      this.showLoadingByQuery();
      student.getStudentClassAttendancePage(this.requestParams).then(res=>{
        this.hideLoading();
        let data = res.data;
        if(append){
          this.list = [...this.list,...data.list];
        }else {
          this.list = data.list;
        }
        this.maxPageNum = data.totalPage;
      }).catch(()=>{
        this.hideLoading();
        if(append && this.requestParams.page > 1){
          this.requestParams.page--;
        }
      })
    }
  }

}

</script>

<style scoped>

</style>
